﻿var project_data;
/*加载project列表start*/
function load_project_list(){
	var _url=cgipath+"project-showlist";
	var ajax_obj=new AJAX_OBJ(_url,handle_load_project_list,handle_error,5000);
	ajax_obj.postData();
}

function handle_load_project_list(xmlHttp){
	eval("var ret_json="+xmlHttp.responseText);
	var str="<select name=\"project_id\">";
	str+="<option value=\"0\">根目录</option>"
	project_data=ret_json.listdata;
	showlist_frame();
	showlist_module();
	showlist_component();
}


var frame_list;
var module_list;
var comment_list;

/*****frame list********/
var page=1;//第1页
var reqnum=10;//每页显示10条
var order="id";//排序字段
var desc="1";//反序,0或空正常排序，1反序
var page_nums=0;

function showlist_frame(){

	var _url=cgipath+"code-showlist";
	var ajax_obj=new AJAX_OBJ(_url,handle_showlist_frame,handle_error,5000);
	ajax_obj.postData("&code_flag=1&type=0&page="+page+"&reqnum="+reqnum+"&order="+order+"&desc="+desc);
}

function handle_showlist_frame(xmlHttp){
	//$$("message").innerHTML=xmlHttp.responseText;return;
	eval("var ret_json="+xmlHttp.responseText);
	frame_list=ret_json.listdata;
	var str="<table><thead><tr><td colspan=3>框架列表</td></tr><tr>";
	str+="<td><a href='javascript:order=\"id\";desc=bin_exchange(desc);list_page_frame(0)'>序号</a></td>";
	str+="<td><a href='javascript:order=\"name\";desc=bin_exchange(desc);list_page_frame(0)'>名称</a></td>";
	str+="<td><a href='javascript:order=\"project_id\";desc=bin_exchange(desc);list_page_frame(0)'>项目</a></td>";
	str+="</tr></thead>";
	for(var i=0;i<ret_json.listdata.length;i++){
		str+="<tr><td>"+((page-1)*reqnum+i+1)+"</td>";
		str+="<td><a href=\"javascript:void(0);\" onclick=\"code_immediate(0,"+i+")\">⊙</a>"
		str+="&nbsp;<a href=\"javascript:void(0);\" onclick=\"pick_parm("+ret_json.listdata[i].id+")\">"+ret_json.listdata[i].name+"</a></td>";
		var parent_str="";
		if(ret_json.listdata[i].project_id==0)parent_str="根目录";
		for(var j=0;j<project_data.length;j++){
			if(project_data[j].id==ret_json.listdata[i].project_id)parent_str=project_data[j].name;;
		}
		str+="<td>"+parent_str+"</td>";
		str+="</tr>";
	}
	page_nums=Math.ceil(ret_json.nums/reqnum);
	str+="<tr><td colspan=2>共"+ret_json.nums+"条，每页"+reqnum+"条，"+page+"/"+page_nums+"</td>";
	str+="<td><a href='#' onclick='list_page_frame(-1)'>上一页</a><a href='#' onclick='list_page_frame(1)'>下一页</a></td></tr>";
	str+="</table>";
	$$("listbox_frame").innerHTML=str
}

/*列表翻页*/
function list_page_frame(t){
	page=page-(-1)*t;
	if(page<=0)page=1;
	else if(page>page_nums) page=page_nums;
	showlist_frame();
}


/*****module list********/
var page=1;//第1页
var reqnum=10;//每页显示10条
var order="id";//排序字段
var desc="1";//反序,0或空正常排序，1反序
var page_nums=0;

function showlist_module(){
	
	var _url=cgipath+"code-showlist";
	var ajax_obj=new AJAX_OBJ(_url,handle_showlist_module,handle_error,5000);
	ajax_obj.postData("&code_flag=1&type=1&page="+page+"&reqnum="+reqnum+"&order="+order+"&desc="+desc);
}

function handle_showlist_module(xmlHttp){
	//$$("message").innerHTML=xmlHttp.responseText;return;
	eval("var ret_json="+xmlHttp.responseText);
	module_list=ret_json.listdata;
	var str="<table><thead><tr><td colspan=3>模块列表</td></tr><tr>";
	str+="<td><a href='javascript:order=\"id\";desc=bin_exchange(desc);list_page_module(0)'>序号</a></td>";
	str+="<td><a href='javascript:order=\"name\";desc=bin_exchange(desc);list_page_module(0)'>名称</a></td>";
	str+="<td><a href='javascript:order=\"project_id\";desc=bin_exchange(desc);list_page_module(0)'>项目</a></td>";
	str+="</tr></thead>";
	for(var i=0;i<ret_json.listdata.length;i++){
		str+="<tr><td>"+((page-1)*reqnum+i+1)+"</td>";
		str+="<td><a href=\"javascript:void(0);\" onclick=\"code_immediate(1,"+i+")\">⊙</a>"
		str+="&nbsp;<a href=\"javascript:void(0);\" onclick=\"pick_parm("+ret_json.listdata[i].id+")\">"+ret_json.listdata[i].name+"</a></td>";		var parent_str="";
		if(ret_json.listdata[i].project_id==0)parent_str="根目录";
		for(var j=0;j<project_data.length;j++){
			if(project_data[j].id==ret_json.listdata[i].project_id)parent_str=project_data[j].name;;
		}
		str+="<td>"+parent_str+"</td>";
		str+="</tr>";
	}
	page_nums=Math.ceil(ret_json.nums/reqnum);
	str+="<tr><td colspan=2>共"+ret_json.nums+"条，每页"+reqnum+"条，"+page+"/"+page_nums+"</td>";
	str+="<td><a href='#' onclick='list_page_module(-1)'>上一页</a><a href='#' onclick='list_page_module(1)'>下一页</a></td></tr>";
	str+="</table>";
	$$("listbox_module").innerHTML=str
}

/*列表翻页*/
function list_page_module(t){
	page=page-(-1)*t;
	if(page<=0)page=1;
	else if(page>page_nums) page=page_nums;
	showlist_module();
}



/*****component list********/
var page=1;//第1页
var reqnum=10;//每页显示10条
var order="id";//排序字段
var desc="1";//反序,0或空正常排序，1反序
var page_nums=0;

function showlist_component(){

	var _url=cgipath+"code-showlist";
	var ajax_obj=new AJAX_OBJ(_url,handle_showlist_component,handle_error,5000);
	ajax_obj.postData("&code_flag=1&type=2&page="+page+"&reqnum="+reqnum+"&order="+order+"&desc="+desc);
}

function handle_showlist_component(xmlHttp){
	//$$("message").innerHTML=xmlHttp.responseText;return;
	eval("var ret_json="+xmlHttp.responseText);
	comment_list=ret_json.listdata;
	var str="<table><thead><tr><td colspan=3>组件列表</td></tr><tr>";
	str+="<td><a href='javascript:order=\"id\";desc=bin_exchange(desc);list_page_component(0)'>序号</a></td>";
	str+="<td><a href='javascript:order=\"name\";desc=bin_exchange(desc);list_page_component(0)'>名称</a></td>";
	str+="<td><a href='javascript:order=\"project_id\";desc=bin_exchange(desc);list_page_component(0)'>项目</a></td>";
	str+="</tr></thead>";
	for(var i=0;i<ret_json.listdata.length;i++){
		str+="<tr><td>"+((page-1)*reqnum+i+1)+"</td>";
		str+="<td><a href=\"javascript:void(0);\" onclick=\"code_immediate(2,"+i+")\">⊙</a>"
		str+="&nbsp;<a href=\"javascript:void(0);\" onclick=\"pick_parm("+ret_json.listdata[i].id+")\">"+ret_json.listdata[i].name+"</a></td>";		var parent_str="";
		if(ret_json.listdata[i].project_id==0)parent_str="根目录";
		for(var j=0;j<project_data.length;j++){
			if(project_data[j].id==ret_json.listdata[i].project_id)parent_str=project_data[j].name;;
		}
		str+="<td>"+parent_str+"</td>";
		str+="</tr>";
	}
	page_nums=Math.ceil(ret_json.nums/reqnum);
	str+="<tr><td colspan=2>共"+ret_json.nums+"条，每页"+reqnum+"条，"+page+"/"+page_nums+"</td>";
	str+="<td><a href='#' onclick='list_page_component(-1)'>上一页</a><a href='#' onclick='list_page_component(1)'>下一页</a></td></tr>";
	str+="</table>";
	$$("listbox_component").innerHTML=str
}

/*列表翻页*/
function list_page_component(t){
	page=page-(-1)*t;
	if(page<=0)page=1;
	else if(page>page_nums) page=page_nums;
	showlist_component();
}